﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

// > 1 / > "a" / > {1, 2, 3} / > Len(a) ...
public class SelectCaseComparison : Expression
{
    private readonly Expression _expression;
    private readonly SyntaxToken? _operatorToken;

    internal SelectCaseComparison(SyntaxNode? parent, SyntaxToken operatorToken, Expression expression)
        : base(SyntaxKinds.SelectCaseComparision, parent)
    {
        SetChildField(ref _operatorToken, operatorToken);
        SetChildField(ref _expression, expression);
    }


    internal SelectCaseComparison(SyntaxNode? parent, Expression expression)
        : base(SyntaxKinds.SelectCaseComparision, parent)
    {
        _expression = expression;
    }


    public SyntaxToken? OperatorToken => _operatorToken;

    public Expression Expression => _expression;


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, OperatorToken, Expression);
        base.AcceptVisitor(visitor);
    }
}


public static partial class NodeFactory
{
    public static SelectCaseComparison CreateSelectCaseComparision(SyntaxNode? parent, SyntaxToken operatorToken,
        Expression expression)
    {
        Debug.Assert(SyntaxFacts.IsCompareOperatorUnchecked(operatorToken.Kind));
        return new SelectCaseComparison(parent, operatorToken, expression);
    }


    public static SelectCaseComparison CreateSelectCaseComparision(SyntaxNode? parent, Expression expression)
    {
        return new SelectCaseComparison(parent, expression);
    }
}